﻿using System;
using CodePlex.DnD4eCampaignManager.DnD4e.Interfaces;

namespace CodePlex.DnD4eCampaignManager.DnD4e
{
    public class Location : ILocation, IEquatable<Location>
    {
        public string Description { get; set; }
        public string Distances { get; set; }
        public int? Index { get; set; }
        public string Name { get; set; }
        public string Npcs { get; set; }

        public override bool Equals(object obj)
        {
            if ( ReferenceEquals(null, obj) )
            {
                return false;
            }
            if ( ReferenceEquals(this, obj) )
            {
                return true;
            }
            if ( obj.GetType() != typeof ( Location ) )
            {
                return false;
            }
            return Equals((Location) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = ( Description != null ? Description.GetHashCode() : 0 );
                result = ( result * 397 ) ^ ( Distances != null ? Distances.GetHashCode() : 0 );
                result = ( result * 397 ) ^ ( Index.HasValue ? Index.Value : 0 );
                result = ( result * 397 ) ^ ( Name != null ? Name.GetHashCode() : 0 );
                result = ( result * 397 ) ^ ( Npcs != null ? Npcs.GetHashCode() : 0 );
                return result;
            }
        }

        public bool Equals(Location otherLocation)
        {
            if ( ReferenceEquals(null, otherLocation) )
            {
                return false;
            }
            if ( ReferenceEquals(this, otherLocation) )
            {
                return true;
            }
            return Equals(otherLocation.Description, Description) && Equals(otherLocation.Distances, Distances) && otherLocation.Index.Equals(Index) &&
                   Equals(otherLocation.Name, Name) && Equals(otherLocation.Npcs, Npcs);
        }

        public static bool operator ==(Location left, Location right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Location left, Location right)
        {
            return !Equals(left, right);
        }
    }
}